﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Microsoft.SharePoint.ApplicationPages;
using System.IO;

namespace Vipesolutions.SharePoint.AddWebpartPickerExtension.HttpModule
{
    public class AddWebPartPickerInjectHttpModule : IHttpModule
    {
        #region contructors

        #endregion

        #region properties

        private HttpApplication _application;

        #endregion

        #region IHttpModule Members

        public void Init(HttpApplication context)
        {
            _application = context;
            _application.ReleaseRequestState += AddInject;
        }

        private void AddInject(object sender, EventArgs e)
        {
            if (_application != null && _application.Context != null && _application.Context.CurrentHandler != null)
            {
                if (_application.Context.CurrentHandler is WebPartGalleryPickerPage)
                {
                    _application.Context.Response.Filter = new InjectFilter(_application.Context.Response.Filter);
                }
            }
        }

        public void Dispose()
        {

        }

        #endregion
    }
}
